import axios from 'axios'
import { Message } from 'element-ui';
import router from "../router";
// 拦截器
axios.interceptors.response.use(success=>{

    //业务逻辑错误
    if (success.status&& success.status == 200){
        if (success.status==500||success.status==401||success.status==403){
            Message.error({message:success.data.message});
            return;
        }
        // 判断有没有信息
        if (success.data.message){
            Message.success({message:success.data.message});
            if (success.data.code==504){
                Message.error({message:success.data.message})
            }
        }

    }
    return success.data;
}, error => {
    if(error.response.status==504||error.response.status==404){
        Message.error({message:"服务器配吃了 囧。。。。"});
    } else if(error.response.code==403){
        Message.error({message:'权限不足'});
    }else if (error.response.code==401){
        Message.error({message:"尚未登录"});
        router.replace('/')}

});

export const postRequest = (urlz, params) => {
    return axios({
        method: 'get',
        url: urlz,
        data: params

    })
};




